home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir36
/
ask_dos.zip
/
ASK.LST
< prev
next >
Wrap
File List
|
1994-03-05
|
17KB
|
429 lines
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 1
ask.asm
1
2 ; *************************************************************************
3 ; * Date: March 31, 1992 Use: Interactive Batch Processing. *
4 ; * *
5 ; * Written by: Patrick Whittle (519) 945-7596 *
6 ; * Revised to .COM format March 5, 1994 *
7 ; *************************************************************************
8
9 =000D CR EQU 0Dh
10 =000A LF EQU 0Ah
11 =0020 SPACE EQU 20h
12
13 comGrp GROUP dSeg1, dSeg2, cSeg
14
15 0000 cSeg SEGMENT WORD 'CODE' ; Give names to our segments.
16 0000 cSeg ENDS
17 0000 dSeg1 SEGMENT WORD PUBLIC 'DATA'
18 0000 dSeg1 ENDS
19 0000 dSeg2 SEGMENT WORD PUBLIC 'DATA'
20 0000 dSeg2 ENDS
21
22 0000 dSeg1 SEGMENT ; Data segment 1 for initialized data.
23 ;
24 0000 42 61 74 63 68 20 45+ MESSAGE DB 'Batch Enhancer, written by Patrick Whittle, (519) 945-7596.', CR, LF, CR, LF
25 6E 68 61 6E 63 65 72+
26 2C 20 77 72 69 74 74+
27 65 6E 20 62 79 20 50+
28 61 74 72 69 63 6B 20+
29 57 68 69 74 74 6C 65+
30 2C 20 28 35 31 39 29+
31 20 39 34 35 2D 37 35+
32 39 36 2E 0D 0A 0D 0A
33 003F 55 53 41 47 45 3A 0D+ DB 'USAGE:', CR, LF
34 0A
35 0047 09 41 53 4B 20 5B 50+ DB 09h, 'ASK [Prompt to display]', CR, LF
36 72 6F 6D 70 74 20 74+
37 6F 20 64 69 73 70 6C+
38 61 79 5D 0D 0A
39 0061 09 41 53 4B 20 5B 2F+ DB 09h, 'ASK [/?]', CR, LF, CR, LF
40 3F 5D 0D 0A 0D 0A
41 006E 52 65 74 75 72 6E 73+ DB 'Returns DOS errorlevel.', CR, LF, 00h
42 20 44 4F 53 20 65 72+
43 72 6F 72 6C 65 76 65+
44 6C 2E 0D 0A 00
45 ;
46 0088 28 59 20 6F 72 20 4E+ PROMPT DB '(Y or N)? ', 00h
47 29 3F 20 00
48 0093 59 45 53 00 YES DB 'YES', 00h
49 0097 4E 4F 00 NO DB 'NO', 00h
50 ;
51 009A 0D 0A 3C 42 72 65 61+ ctrlText DB CR, LF, '<Break>', CR, LF, 00h
52 6B 3E 0D 0A 00
53 00A6 dSeg1 ENDS
54
55 0000 dSeg2 SEGMENT ; Data segment 2 for un-initialized data.
56 ;
57 0000 ?? errorlevel DB ?
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 2
ask.asm
58 0001 ???? origSegment DW ?
59 0003 ???? origOffset DW ?
60 ;
61 0005 dSeg2 ENDS
62
63 0000 cSeg SEGMENT
64
65 ASSUME cs:comGrp, ds:comGrp, es:comGrp, ss:comGrp
66
67 ORG 100h ; Start of CS and DS
68
69 0100 Main:
70 0100 E8 009A call grabCommandline ; Command-line tail given?
71 0103 E3 2B jcxz sendInstruction ; If not, send out prompt.
72
73 0105 81 3C 3F2F cmp WORD PTR [si], '?/'
74 0109 74 2A je sendHelp
75 010B 8B DE mov bx, si ; SI contains pointer to cmd-line argument.
76 010D E8 006B call dispString ; Display user supplied string.
77
78 0110 ContinueMain:
79 0110 E8 00DC call getIntVector
80 0113 BA 01C5r lea dx, ctrlBreakHandler
81 0116 E8 00D0 call setIntVector
82 0119 E8 0026 call Validate ; Compare inputed keys with Y and N.
83
84 011C Stop:
85 011C 1E push ds
86 011D 8B 16 0003r mov dx, comGrp:origOffset
87 0121 8E 1E 0001r mov ds, comGrp:origSegment
88 0125 E8 00C1 call setIntVector
89 0128 1F pop ds
90
91 0129 DOSexit:
92 0129 B4 4C mov ah, 4Ch ; Program Terminate with errorlevel.
93 012B A0 0000r mov al, comGrp:errorlevel
94 012E CD 21 int 21h
95
96 0130 sendInstruction:
97 0130 E8 0041 call OutPut
98 0133 EB DB jmp ContinueMain ; Proceed and validate input.
99
100 0135 sendHelp:
101 0135 BB 0000r lea bx, MESSAGE
102 0138 E8 0040 call dispString
103 013B C6 06 0000r 00 mov comGrp:errorlevel, 00h
104 0140 EB E7 jmp DOSexit
105
106 ;---------------------------
107
108 0142 Validate PROC NEAR
109 0142 E8 0045 call AcceptChar
110 0145 3C 59 cmp al, 'Y' ; Is this the "Y" character?
111 0147 74 0C je YWasTyped
112 0149 3C 4E cmp al, 'N' ; Is this the "N" character?
113 014B 74 18 je NWastyped
114 014D E8 0042 call Cr_Lf
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 3
ask.asm
115 0150 E8 0021 call OutPut ; Conditions not met.
116 0153 EB ED jmp Validate ; Unconditional jump.
117
118 0155 YWasTyped:
119 0155 BB 0093r lea bx, comGrp:YES ; Load Effective Address into BX.
120 0158 E8 0020 call dispString
121 015B E8 0034 call Cr_Lf
122 015E C6 06 0000r 00 mov comGrp:errorlevel, 00h ; Set DOS errorlevel to zero.
123 0163 EB 0E jmp CharactersFine
124
125 0165 NWasTyped:
126 0165 BB 0097r lea bx, comGrp:NO
127 0168 E8 0010 call dispString
128 016B E8 0024 call Cr_Lf
129 016E C6 06 0000r 01 mov comGrp:errorlevel, 01h ; Set DOS errorlevel to one.
130
131 0173 CharactersFine:
132 0173 C3 ret
133
134 0174 Validate ENDP
135
136 0174 Output PROC NEAR
137 0174 BB 0088r lea bx, PROMPT
138 0177 E8 0001 call dispString
139 017A C3 ret ; Return to calling module.
140
141 017B Output ENDP
142
143 017B dispString PROC NEAR
144 017B B4 02 mov ah, 02h
145
146 017D sendPrompt:
147 017D 80 3F 00 cmp BYTE PTR [bx], 00h
148 0180 74 07 je promptDone
149 0182 8A 17 mov dl, BYTE PTR [bx]
150 0184 CD 21 int 21h
151 0186 43 inc bx
152 0187 EB F4 jmp sendPrompt
153
154 0189 promptDone:
155 0189 C3 ret
156
157 018A dispString ENDP
158
159 018A AcceptChar PROC NEAR
160 018A B4 08 mov ah, 08 ; Accept character function.
161 018C CD 21 int 21h
162 018E E8 004D call upCase
163 0191 C3 ret ; Return to calling module.
164
165 0192 AcceptChar ENDP
166
167 0192 Cr_Lf PROC NEAR
168 0192 B4 02 mov ah, 02h
169 0194 B2 0D mov dl, CR
170 0196 CD 21 int 21h
171 0198 B2 0A mov dl, LF
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 4
ask.asm
172 019A CD 21 int 21h
173 019C C3 ret ; Return to calling module.
174
175 019D Cr_Lf ENDP
176
177 019D grabCommandline PROC NEAR
178 ;
179 ; Any command-line parameters supplied by the user will be passed by DOS into
180 ; the executing programs PSP (Program Segment Prefix) area. The default PSP
181 ; area in a program, weather in .EXE format or .COM format, is between offset
182 ; 0000 and 0100h of the programs data segment. Since a program in .COM format
183 ; has its code, data, and stack stored in the same segment of memory
184 ; (i.e. CS=DS=SS respectively) it is necessary that the code of .COM programs
185 ; always starts at offset 0100h (see ORG directive at start of this program).
186 ;
187 ; This PROCedure uses SI register to access the PSP making use of a flag set
188 ; by DOS at offset 80h. This single byte indicates weather a command-line
189 ; argument was supplied or not. If the value at offset 80h is zero, then
190 ; no command-line argument was supplied. If the value is non-zero, the
191 ; contents of offset 80h will hold a byte count for the supplied argument.
192 ;
193 ; In this procedure, the CX register will receive a copy of the byte at
194 ; offset 80h to be used in calculating the end address of the string. All
195 ; preceding, and trailing spaces will be discarded.
196 ;
197 ; Inputs:
198 ; None
199 ;
200 ; Output:
201 ; si - Pointer to start of user supplied string.
202 ; cx - zero if no command-line argument given.
203 ;
204 ; Registers modified:
205 ; cx, si
206 ;
207 019D 33 C9 xor cx, cx ; Zero out cx register.
208 019F BE 0080 mov si, 80h
209 01A2 80 3C 00 cmp BYTE PTR [si], 00h
210 01A5 74 1D je grabDone ; If byte at offset 80h is 0 then there were
211 ; no arguments.
212 01A7 8A 0C mov cl, BYTE PTR [si] ; Move byte pointed to by SI into CL register.
213
214 01A9 findNonblank:
215 01A9 46 inc si
216 01AA 80 3C 20 cmp BYTE PTR [si], SPACE
217 01AD 75 02 jne startFound
218 01AF E2 F8 loop findNonblank ; Assume length of argument is one less now
219 ; as loop decrements CX register.
220 01B1 startFound:
221 01B1 E3 11 jcxz grabDone ; If CX is zero then the user has supplied
222 ; a string of spaces and just pressed ┘
223 01B3 56 push si ; Save start of argument.
224 01B4 03 F1 add si, cx ; To point to end.
225
226 01B6 testForTrailingBlank:
227 01B6 4E dec si
228 01B7 80 3C 20 cmp BYTE PTR [si], SPACE
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 5
ask.asm
229 01BA 75 02 jne terminateArgument
230 01BC E2 F8 loop testForTrailingBlank ; Remove unwanted spaces.
231
232 01BE terminateArgument:
233 01BE C7 44 01 0020 mov WORD PTR [si+1], 0020h ; Add space and ensure string is ASCIIZ.
234 01C3 5E pop si
235
236 01C4 grabDone:
237 01C4 C3 ret
238
239 01C5 grabCommandline ENDP
240
241 01C5 ctrlBreakHandler PROC NEAR
242 ;
243 ; This PROCedure is the replacement interrupt handler for int 23h - the
244 ; Ctrl-Break interrupt. Regardless where the machine is currently executing
245 ; in memory, the Ctrl-C interrupt will instantly force execution to branch
246 ; to this area. The int 23h handler will be restored when ASK.COM terminates.
247 ;
248 ; The value of all segment registers will be unchanged when an interrupt is
249 ; encountered. Since this program is not a TSR (Terminate and Stay Resident)
250 ; we don't need to worry about initializing DS to point to our data for
251 ; example, or any other segment registers.
252 ;
253 ; If this were a TSR program or device driver on the other hand, segment
254 ; registers would not contain values reflecting the location of code, data,
255 ; etc., for ASK.COM, they would contain values that were part of some other
256 ; executing program at the time of the interrupt.
257 ;
258 ; The way the internal interrupt vectors are designed on Intel machines is
259 ; such that only the CS:IP registers (code segment:instruction pointer) are
260 ; modified when a certain interrupt is encountered, and a FAR return address
261 ; is then pushed onto the stack (segment:offset = current execution address
262 ; of interrupted program). It is up to the "interruptor" (i.e. the device
263 ; driver, or TSR program) to first set up segment registers to point to its
264 ; needed data, stack etc., and when finished, restore CS:IP with an iret
265 ; instruction once the service requested of the device driver is complete.
266 ;
267 ; Output:
268 ; Program terminates with DOS errorlevel 2
269 ;
270 ; Registers modified:
271 ; ax, bx, cx
272 ;
273 01C5 8C C8 mov ax, cs ; The next three move intstructions are
274 01C7 8E D8 mov ds, ax ; not needed in the context of this program,
275 01C9 8E C0 mov es, ax ; but are included for demonstration.
276 01CB C6 06 0000r 02 mov comGrp:errorlevel, 02h
277 01D0 BB 009Ar lea bx, comGrp:ctrlText
278 01D3 E8 FFA5 call dispString
279
280 01D6 B8 0C00 mov ax, 0C00h ; Flush keyboard buffer.
281 01D9 CD 21 int 21h
282 01DB E9 FF3E jmp Stop
283
284 01DE ctrlBreakHandler ENDP
285
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 6
ask.asm
286 01DE upCase PROC NEAR
287 ;
288 ; This function returns the corresponding upper-case letter for
289 ; the lower-case letter passed in al.
290 ;
291 ; Input:
292 ; al - contains the ASCII value for a lower-case letter
293 ; Output:
294 ; al - contains the ASCII value for the corresponding upper-case
295 ; letter.
296 ;
297 ; Registers modified:
298 ; al
299 ;
300 ; Convert the letter in AL to upper-case.
301 ;
302 01DE 3C 61 cmp al, 'a'
303 01E0 72 06 jb upcas1
304 01E2 3C 7A cmp al, 'z'
305 01E4 77 02 ja upcas1
306 01E6 2C 20 sub al, 20h
307
308 01E8 upcas1:
309 01E8 C3 ret
310
311 01E9 upCase ENDP
312
313 01E9 setIntVector PROC NEAR
314 ;
315 ; DX register must be initialized first before calling.
316 ;
317 01E9 B8 2523 mov ax, 2523h
318 01EC CD 21 int 21h
319 01EE C3 ret
320
321 01EF setIntVector ENDP
322
323 01EF getIntVector PROC NEAR
324 01EF 06 push es
325 01F0 B8 3523 mov ax, 3523h ; 23 is ctrl-break location in interrupt
326 01F3 CD 21 int 21h ; vector table.
327
328 01F5 8C 06 0001r mov WORD PTR comGrp:origSegment, es
329 01F9 89 1E 0003r mov WORD PTR comGrp:origOffset, bx
330 01FD 07 pop es
331 01FE C3 ret
332
333 01FF getIntVector ENDP
334
335 01FF cSeg ENDS
336
337 END Main
Turbo Assembler Version 3.1 03/05/94 15:17:09 Page 7
Symbol Table
Symbol Name Type Value
??DATE Text "03/05/94"
??FILENAME Text "ask "
??TIME Text "15:17:09"
??VERSION Number 030A
@CPU Text 0101H
@CURSEG Text CSEG
@FILENAME Text ASK
@WORDSIZE Text 2
ACCEPTCHAR Near CSEG:018A
CHARACTERSFINE Near CSEG:0173
CONTINUEMAIN Near CSEG:0110
CR Number 000D
CR_LF Near CSEG:0192
CTRLBREAKHANDLER Near CSEG:01C5
CTRLTEXT Byte DSEG1:009A
DISPSTRING Near CSEG:017B
DOSEXIT Near CSEG:0129
ERRORLEVEL Byte DSEG2:0000
FINDNONBLANK Near CSEG:01A9
GETINTVECTOR Near CSEG:01EF
GRABCOMMANDLINE Near CSEG:019D
GRABDONE Near CSEG:01C4
LF Number 000A
MAIN Near CSEG:0100
MESSAGE Byte DSEG1:0000
NO Byte DSEG1:0097
NWASTYPED Near CSEG:0165
ORIGOFFSET Word DSEG2:0003
ORIGSEGMENT Word DSEG2:0001
OUTPUT Near CSEG:0174
PROMPT Byte DSEG1:0088
PROMPTDONE Near CSEG:0189
SENDHELP Near CSEG:0135
SENDINSTRUCTION Near CSEG:0130
SENDPROMPT Near CSEG:017D
SETINTVECTOR Near CSEG:01E9
SPACE Number 0020
STARTFOUND Near CSEG:01B1
STOP Near CSEG:011C
TERMINATEARGUMENT Near CSEG:01BE
TESTFORTRAILINGBLANK Near CSEG:01B6
UPCAS1 Near CSEG:01E8
UPCASE Near CSEG:01DE
VALIDATE Near CSEG:0142
YES Byte DSEG1:0093
YWASTYPED Near CSEG:0155
Groups & Segments Bit Size Align Combine Class
COMGRP Group
CSEG 16 01FF Word none CODE
DSEG1 16 00A6 Word Public DATA
DSEG2 16 0005 Word Public DATA